<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>
	<body>
		<input type="text" />
		<button>submit</button>
		<div></div>
		<script>
			let str = '   darkgreen   dkh   ';
			console.log(str);
			// trim 方法去除两侧空格   不去除中间的
			let str1 = str.trim();
			console.log(str1);

			let input = document.querySelector('input');
			let btn = document.querySelector('button');
			let div = document.querySelector('div');

			btn.onclick = function () {
				let str = input.value.trim();
				if (str === '') {
					alert('请输入内容');
				} else {
					console.log(str);
					console.log(str.length);

					div.innerHTML = str;
				}
			};
		</script>
	</body>
</html>
